<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<body>
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-sm" lay-event="add_panel">新增</button>
  	</div>
</script>
	<fieldset class="layui-elem-field layui-field-title site-title">
		<legend><a name="fixbar" style="font-size: 16px; color: #ce2424;">班级管理</a></legend>
	</fieldset>
	<form class="layui-form" action="save" id="myForm" method="post" lay-filter="stuform">
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">班级名称：</label>
				<div class="layui-input-inline">
					<input type="text" name="name" id="tbClassName" value="${param.name}" class="layui-input" />
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">培训主题：</label>
				<div class="layui-input-inline">
					<input type="text" name="subject" id = "subject" value="${param.subject}" class="layui-input" />
				</div>
			</div>
			
			<div class="layui-inline">
				<input type="checkbox" id="btnType" title="是否结业">
				<button type="button" class="layui-btn layui-btn-danger" onclick="search()">查询</button>
				<button type="button" class="layui-btn layui-btn-danger" onclick="empty()">清空</button>
			</div>
		</div>
	</form>

	<script type="text/html" id="barDemo3">
  		<button class="layui-btn layui-btn-sm" lay-event="update_panel2">修改</button>
		<button class="layui-btn layui-btn-sm" lay-event="delete2">删除</button>
		<button class="layui-btn layui-btn-sm" lay-event="grouping">分组</button>
		<button class="layui-btn layui-btn-sm" lay-event="view3">显示</button>
	</script>
	
	<table class="layui-hide" id="tbClass" lay-filter="tbClass"></table>
	
	<form style="display: none;" class="layui-form" id = "home">
		<div class="layui-form-item" style="margin-top: 45px">
			<label class="layui-form-label">组数：</label>
			<div class="layui-input-inline">
				<input type="text" name="zs" id="zs" class="layui-input" />
			</div>
		</div>
	</form>
	
	<script type="text/javascript">
		var option={
			elem:'#tbClass',
			title:'班级',
			path:'tbClass',
			addurl:'edit',
			height:'full-265',
			where:{name:'${param.name}',subject:'${param.subject}'},
			toolbar:'#toolbarDemo',
			cols: [[
				{field: 'id', title: 'ID', hide: true, usersize: true, sort: true},
				{field: 'name', title: '班级名称'},
				{field: 'subject',hide: true,  title: '培训主题'},
				{field: 'ctype',hide: true,  title: '班级类型', templet: function(d){
					return d.ctype?d.ctype.type: '';
				}},
				{field: 'classSize', title: '班级人数'},
				{field: 'regBeginTime',hide: true,  title: '报名开始时间'},
				{field: 'regEndTime',hide: true,  title: '报名结束时间'},
				{field: 'startTime',hide: true,  title: '开班日期'},
				{field: 'closeTime',hide: true,  title: '结业日期'},					
				{field: 'state', title: '班级状态', templet: function(d){
					return d.classStatus?d.classStatus.state: '';
				}},					
				{field: 'memo',hide: true,  title: '备注'},	
				{field:'teacherId',title:'班主任',templet: function(d){
					return d.teacherId?d.teacherId.name: '';
				}},
				{fixed: 'right', title:'操作', toolbar: '#barDemo3', width:280}
			]]
		};
		var currRow="${param.currRow==null?'null':param.currRow}";
		var limit=${param.limit==null?'null':param.limit};
		var page=${param.page==null?'null':param.page};
		var classTable=new LayUiTable(option,currRow,limit,page);
		classTable.init();
		
		layui.use('form', function(){
			var form = layui.form;
			form.render();
		})
		
		layui.use('table', function(){
			var table = layui.table;
			table.on('tool(tbClass)', function(obj){
				var id = obj.data.id;
				if(obj.event === "grouping"){
					$("#content").load("${pageContext.request.contextPath }/tbClass/groupMsg?id="+id)
				}
			});
		});
		
		function search(){
			var tbClassName = $("#tbClassName").val();
			var subject = $("#subject").val();
			var btnType = '';
			var checked = document.getElementById("btnType").checked;
			if(checked){
				btnType="yes";
			}else{
				btnType="no";
			}
			layui.use('table', function(){
				var table = layui.table;
				classTable.ops.where={tbClassName: tbClassName, btnType: btnType, subject: subject};
				table.reload('id',{
					url:'tbClass/page',
					where: {
						name: tbClassName,
						btnType: btnType,
						subject: subject
					}
				});
			});
		}
		
		function empty(){
			classTable.ops.where="";
			$("#myForm input,textarea,select").val("");
			$("#btnType").prop('checked', false);
			layui.use('form', function(){
				var form = layui.form;
				form.render();
			});
			table.reload('id',{
				url:'tbClass/page',
				where: ''
			});
		}
	</script>
</body>
